function handleFileSelect(event: Event) {
		const input = event.target as HTMLInputElement;
		if (input.files && input.files.length > 0) {
			selectedFile = input.files[0];
		} else {
			console.log("null");
			selectedFile = null; // 如果没有文件，设置为空
		}
	}

	async function handleImageUpload() {
		if (!selectedFile) {
			showNotification("请选择图片", "error");
			return;
		}

		uploading = true;
		const formData = new FormData();
		if (selectedFile instanceof File) {
			const newFileName = "test.png"; // 设定新文件名

			const renamedFile = new File([selectedFile], newFileName, {
				type: selectedFile.type,
			});

			formData.append("file", renamedFile, renamedFile.name);
		} else {
			showNotification("上传文件无效", "error");
			uploading = false;
			return;
		}
		formData.forEach((value, key) => {
			console.log(key, value);
		});
		try {
			const res = await uploadImageToServer(formData);
			console.log('完整响应:', res); // 完整打印响应
			
			if (res.status === "success") {
				showNotification(res.message || `图片上传成功：${res.file_name}`, "success");
				// showNotification(`保存路径：${res.file_path}`, "info");

				// 新增：触发自定义事件，将 "@Image" 传递给父组件
				const event = new CustomEvent('imageUploaded', { 
					detail: { 
						imageText: "@Image" 
					} 
				});
				window.dispatchEvent(event);

				selectedFile = null;
				imageUploaded = true;

				// 2秒后自动关闭抽屉
				autoCloseTimer = setTimeout(() => {
					hidden6 = true;
				}, 2000) as unknown as number;

				// 重置文件输入
				const fileInput = document.getElementById(
					"imageUpload"
				) as HTMLInputElement;
				if (fileInput) fileInput.value = "";
			} else {
				const errorMessage = res.message || "图片上传失败，请重试";
				showNotification(`上传失败：${errorMessage}`, "error");
			}
		} catch (error) {
			const errorMsg = error instanceof Error ? error.message : String(error);
			console.error('上传错误:', error); // 增加错误日志
			showNotification(`上传出错：${errorMsg}`, "error");
		} finally {
			uploading = false;
		}
	}

	function showNotification(text: string, type: string) {
		addNotification({
			text: text,
			position: "top-left",
			type: type,
			removeAfter: 3000,
		});
	}